import 'package:flutter/material.dart';
import 'package:flutter_syt/domain/widgets/network_load_image.dart';
import 'package:flutter_syt/routes.all.dart';
import 'package:flutter_syt/theme/font_styles.dart';
import 'package:flutter_syt/theme/theme_color.dart';
import 'package:flutter_syt/utils/click_utils.dart';
import 'package:yyy_route_annotation/yyy_route_annotation.dart';

class NewsCardEntity {
  late Text text;
  late String image;
  late GestureTapCallback? onTap;
  late double? fontSize;
  late double? width;
  late double? height;
  late Color? color;

  NewsCardEntity();

  factory NewsCardEntity.create(
    String text,
    String image, {
    GestureTapCallback? onTap,
    double? fontSize= 14.0,
    double? width= double.infinity,
    double? height,
    Color? color,
  }) {
    return NewsCardEntity()
      ..text = Text(
        text,
        maxLines: 2,
        softWrap: false,
        textAlign: TextAlign.left,
        overflow: TextOverflow.ellipsis,
        style: FontStyles.headerTextStyle_14.copyWith(
          color: color ?? ThemeColor.bkColorFFFFFF,
          fontSize: fontSize,
        ),
      )
      ..width = width
      ..height = height
      ..image = image
      ..onTap = onTap;
  }

  static NewsCardEntity fakeData(BuildContext context) {
    return NewsCardEntity.create(
      "残奥赛会各项目竞委会新闻宣传及媒体运行工作会议在西安召开",
      "https://avatars2.githubusercontent.com/u/20411648?s=460&v=4",
      onTap: ClickUtils.debounce(() => RouteManager.push(
            context,
            RoutMapping.testList(),
          )),
      // width: 140,
      height: 220,
    );
  }
}

// 新闻卡片
class NewsCard extends StatelessWidget {
  final NewsCardEntity entity;
  const NewsCard(this.entity, {Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: ClickUtils.debounce(
        () => entity.onTap,
      ),
      child: Stack(
        children: [
          Container(
            width: entity.width,
            height: entity.height,
            // decoration: BoxDecoration(
            //   // color: Colors.white,
            //   image: NetworkLoadImage.loadNetworkProviderImage(entity.image),
            //   borderRadius: BorderRadius.all(const Radius.circular(12)),
            // ),
            child: ClipRRect(
              borderRadius: BorderRadius.circular(12),
              child: NetworkLoadImage.loadNetworkImage(entity.image,
                  settingMax: true),
              // child: ImageLoader.loadImage(imageUrl: entity.image),
            ),
          ),
          Positioned(
            bottom: 16,
            left: 0,
            right: 0,
            child: Container(
              padding: EdgeInsets.only(left: 10, right: 16),
              child: entity.text,
            ),
          ),
        ],
      ),
    );
  }
}
